﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using Model;

namespace BusinessLogic
{
    public class GetCarSeriesCommand : BaseCommand<acm_car_series>
    {
        public int id;
        public string series;
        public string subseries;

        public GetCarSeriesCommand(int sid)
        {
            id = sid;

            SetQuery("select id, car_series, car_sub_series from acm_car_series where id=@id");

            cmd.Parameters.AddWithValue("id", id);
        }

        public GetCarSeriesCommand(string car_series, string car_sub_series, string car_model_suffix)
        {
            //series = car_series;
            //subseries = car_sub_series;

            SetQuery("select id, car_series, car_sub_series from acm_car_series where car_series=@series and car_sub_series=@subseries and car_model_suffix=@suffix");

            cmd.Parameters.AddWithValue("series", car_series);
            cmd.Parameters.AddWithValue("subseries", car_sub_series);
            cmd.Parameters.AddWithValue("suffix", car_model_suffix);
        }


        public override void Command()
        {
            SqlDataReader dr = cmd.ExecuteReader();
            if(dr.HasRows)
            {
                dr.Read();
                Result = new acm_car_series();
                Result.id = GetNullableInt(dr, 0);
                Result.car_series = GetNullableString(dr, 1);
                Result.car_sub_series = GetNullableString(dr, 2);
            }
        }
    }
}
